package com.ruoyi.orderEat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.orderEat.domain.ShopSkuInfoVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.orderEat.domain.ShopSkuInfo;
import com.ruoyi.orderEat.service.IShopSkuInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品规格Controller
 * 
 * @author DingHao
 * @date 2023-11-24
 */
@RestController
@RequestMapping("/orderEat/sku")
public class ShopSkuInfoController extends BaseController
{
    @Autowired
    private IShopSkuInfoService shopSkuInfoService;

    /**
     * 查询商品规格列表
     */
    @PreAuthorize("@ss.hasPermi('orderEat:sku:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopSkuInfo shopSkuInfo)
    {
        startPage();
        List<ShopSkuInfoVO> list = shopSkuInfoService.selectShopSkuInfoList(shopSkuInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品规格列表
     */
    @PreAuthorize("@ss.hasPermi('orderEat:sku:export')")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopSkuInfo shopSkuInfo)
    {
        List<ShopSkuInfoVO> list = shopSkuInfoService.selectShopSkuInfoList(shopSkuInfo);
        ExcelUtil<ShopSkuInfoVO> util = new ExcelUtil<ShopSkuInfoVO>(ShopSkuInfoVO.class);
        util.exportExcel(response, list, "商品规格数据");
    }

    /**
     * 获取商品规格详细信息
     */
    @PreAuthorize("@ss.hasPermi('orderEat:sku:query')")
    @GetMapping(value = "/{shopSkuId}")
    public AjaxResult getInfo(@PathVariable("shopSkuId") Long shopSkuId)
    {
        return success(shopSkuInfoService.selectShopSkuInfoByShopSkuId(shopSkuId));
    }

    /**
     * 新增商品规格
     */
    @PreAuthorize("@ss.hasPermi('orderEat:sku:add')")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopSkuInfo shopSkuInfo)
    {
        return toAjax(shopSkuInfoService.insertShopSkuInfo(shopSkuInfo));
    }

    /**
     * 修改商品规格
     */
    @PreAuthorize("@ss.hasPermi('orderEat:sku:edit')")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopSkuInfo shopSkuInfo)
    {
        return toAjax(shopSkuInfoService.updateShopSkuInfo(shopSkuInfo));
    }

    /**
     * 删除商品规格
     */
    @PreAuthorize("@ss.hasPermi('orderEat:sku:remove')")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{shopSkuIds}")
    public AjaxResult remove(@PathVariable Long[] shopSkuIds)
    {
        return toAjax(shopSkuInfoService.deleteShopSkuInfoByShopSkuIds(shopSkuIds));
    }
}
